const axios = require('axios');
const cheerio = require('cheerio');
const fs = require('fs');

const url = 'https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools';

async function fetchPageInfo() {
    try {
        // 发送 HTTP 请求获取网页内容
        /*
        const { data } = await axios.get(url);
        // 使用 cheerio 加载 HTML        
        const $ = cheerio.load(data);
        */

        const buffer = fs.readFileSync('qq.html');
        const $ = cheerio.loadBuffer(buffer);
        // console.log('$:', $);

        // 提取 "More Info" 部分的信息
        const moreInfo = {};

        // 提取版本号
        // moreInfo.version = $('.ux-item-details-version').text().trim();
        // moreInfo.version = $('td,[aria-labelledby="version"]').text().trim();
        // moreInfo.version = $('#overviewTab > div > table > tbody > tr > td.ux-itemdetails-right > div.itemDetails-right > div.ux-section-other > h3').html();
        moreInfo.version = $('#version-history-tab-content > div > div.ms-Grid.version-history-container-grid').text();
        // 提取发布日期
        moreInfo.releasedOn = $('.ux-item-details-released-on').text().trim();

        // 提取最后更新日期
        moreInfo.lastUpdated = $('.ux-item-details-last-updated').text().trim();

        // 提取发布者
        moreInfo.publisher = $('.ux-item-details-publisher').text().trim();

        // 提取唯一标识符
        // moreInfo.uniqueIdentifier = $('td,[aria-labelledby="unique-identifier"]').text().trim();
        moreInfo.uniqueIdentifier = $('.ux-item-details-unique-identifier').text().trim();


        // 打印提取的信息
        console.log('More Info:', moreInfo);
    } catch (error) {
        console.error('Error fetching page info:', error);
    }
}

fetchPageInfo();